export default {
  data () {
    return {
      // 控制步骤条
      activeIndex: 1,
      // 控制tabs
      activeName: 'two',
      // 添加商品表单对象
      addGoodsForm: {
        goods_name: '',
        goods_cat: [],
        goods_price: '',
        goods_number: '',
        goods_weight: '',
        goods_introduce: '',
        pics: [], // 图片
        // 单选框
        radio: true
      },
      // 级联选择器的数据
      options: [
        {
          value: 'ziyuan',
          label: '资源',
          children: [
            {
              value: 'axure',
              label: 'Axure Components'
            },
            {
              value: 'sketch',
              label: 'Sketch Templates'
            },
            {
              value: 'jiaohu',
              label: '组件交互文档'
            }
          ]
        }
      ],
      // 配置
      defaultPorps: {
        label: 'cat_name',
        value: 'cat_id'
      },
      // 上传图片所需要的配置
      dialogImageUrl: '',
      dialogVisible: false,
      // 请求头对象
      headers: {
        Authorization: localStorage.getItem('token')
      }
    }
  },
  created () {
    this.loadCatData()
  },
  methods: {
    clickTab (tab) {
      console.log('tab:', tab)
      this.activeIndex = +tab.index + 1
    },
    // 下一步
    next (index, name) {
      this.activeIndex = index
      this.activeName = name
    },
    async loadCatData () {
      let res = await this.$axios.get('categories', {
        params: {
          type: 3
        }
      })
      console.log(res)
      this.options = res.data.data
    },
    // 上传图片配置相关的方法
    handleRemove (file, fileList) {
      console.log(file, fileList)
    },
    handlePictureCardPreview (file) {
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },
    // 图片上传成功
    uploadSuccess (res) {
      console.log(res)
      this.addGoodsForm.pics.push({
        pic: res.data.tmp_path
      })
    }
  }
}
